Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes handling of deferred payments (ask to buy) #296

Merged

Conversation

vegaro
Copy link
Contributor

@vegaro vegaro commented Jul 27, 2020

Should fix #273

In order to test it add:

    payment.simulatesAskToBuyInSandbox = YES;

to the SKMutablePayment. This flag will trigger a SKPaymentTransactionStateDeferred. The flow in sandbox is not the same as in production. In production, guardians get a notification with an approval request. In sandbox I have only managed to get that SKPaymentTransactionStateDeferred transaction.

Please note that we are not finishing the transaction. The documentation is not clear, but looking at https://developer.apple.com/documentation/storekit/in-app_purchase/offering_completing_and_restoring_in-app_purchases, it looks like we only need to "Call finishTransaction(_:) on transactions whose state is SKPaymentTransactionState.failed, SKPaymentTransactionState.purchased, or SKPaymentTransactionState.restored to remove them from the queue."

@vegaro vegaro requested a review from aboedo July 28, 2020 03:38
@@ -1039,7 +1039,26 @@ - (void)storeKitWrapper:(RCStoreKitWrapper *)storeKitWrapper
}
break;
}
case SKPaymentTransactionStateDeferred:
case SKPaymentTransactionStateDeferred: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@aboedo aboedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great 👍 I left a couple of suggestions

Comment on lines 1047 to 1051
NSError *pendingError = [NSError errorWithDomain:RCPurchasesErrorDomain
code:RCPaymentPendingError
userInfo:@{
NSLocalizedDescriptionKey: @"The payment is deferred."
}];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pendingError,
transaction.error.code == SKErrorPaymentCancelled);
@synchronized (self) {
self.purchaseCompleteCallbacks[transaction.payment.productIdentifier] = nil;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should start checking if transaction, transaction.payment and transaction.payment.productIdentifier aren't nil before doing this. otherwise we could run into issues like ##279

On another note, we might not need to make two locks - why not unify the synchronize calls?

@synchronized (self) {
    completion = self.purchaseCompleteCallbacks[transaction.payment.productIdentifier];
    self.purchaseCompleteCallbacks[transaction.payment.productIdentifier] = nil;
}

the block should be copied anyway, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good point! Regarding the blocks, yes, I think we can combine the synchronized blocks

Copy link
Member

@aboedo aboedo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! :shipit:

@vegaro vegaro merged commit de0af8e into develop Aug 1, 2020
@vegaro vegaro deleted the cesardelavega/ch310/handle-deferred-payments-on-ios-ask-to-buy branch August 1, 2020 00:51
@vegaro vegaro mentioned this pull request Aug 4, 2020
@aboedo aboedo mentioned this pull request Aug 27, 2020
@aboedo aboedo mentioned this pull request Sep 10, 2020
@aboedo aboedo mentioned this pull request Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

completion block won't be called for deferred purchases
3 participants